# -*- coding: utf-8 -*-
"""
Created on Thu Aug 08 23:24:11 2013

@author: Jeanhwea
"""
from time import sleep
import os
from random import randint
#reload(sys)
#sys.setdefaultencoding('utf8')
base = '../inputfile/'

sender = ''
receiver = ''
password = ''
subject = ''
message = ''
ary_snd = []
ary_psw = []
ary_rcv = []
ary_sub = ['Ha', 'La', 'Ta', 'Tr', 'Pw', 'Rt', 'Qt', 'Se', 'Qw', 'Fw']
ary_msg = []

with open(base + 'scsesender.txt', 'r') as f_snd:
    with open(base + 'receiver.txt', 'r') as f_rcv:
        with open(base + 'message.txt', 'r') as f_msg:
            for line in f_snd:
                ary_snd.append(line.split()[0])
                ary_psw.append(line.split()[1])
            for lin in f_rcv:
                ary_rcv.append(lin.split()[0])
            for li in f_msg:
                ary_msg.append(li)
        f_msg.close()
    f_rcv.close()
f_snd.close()

size_snd = len(ary_snd)
size_rcv = len(ary_rcv)
size_msg = len(ary_msg)
size_sub = len(ary_sub)
times = 1
index_msg = 0
while True:
    if times > 10:
        break
    index_snd = randint(1, size_snd)
    index_rcv = 1 #randint(2, size_rcv)
    index_sub = randint(1, size_sub)
    index_msg += 1
    sender   = ary_snd[index_snd-1]
    password = ary_psw[index_snd-1]
    receiver = ary_rcv[index_rcv-1]
    subject  = ary_sub[index_sub-1]
    message  = ary_msg[(index_msg % size_msg) - 1]
    cmd = ' '.join(['python xsmtp.py',password,
                    sender,receiver,subject,message])
    os.system(cmd)
    times += 1
    sleep(5)
